package org.syg.generator.util;

import org.syg.generator.config.DataSourceConfig;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author ps
 */
public class JdbcUtil {

    private JdbcUtil() {
    }


    /**
     * 获得执行sql结果
     *
     * @return
     * @throws ClassNotFoundException
     * @throws SQLException
     */
    public static ResultSet executeQuery(DataSourceConfig dbConfig, String sql) throws SQLException {
        // 加载数据库驱动 Class.forName(dbConfig.getDriverName());
        Connection connection = DriverManager.getConnection(dbConfig.getJdbcUrl(), dbConfig.getUsername(), dbConfig.getPassword());

        PreparedStatement statement = connection.prepareStatement(sql);

        return statement.executeQuery();
    }
}
